home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / IW-Half-Dither / source / ChooserSupportPACK.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.9 KB  |  187 lines  |  [TEXT/MPS ]

  1. /*
  2.     ChooserSupport.c - C code for PACK and LDEF resources used by the Chooser.
  3.     
  4.     Copyright © 1992-1994 Apple Computer, Inc.
  5.     All rights reserved.
  6.  
  7.     12/20/93        dmh                Sync'd with the shipping 1.0b3 GX driver.
  8.      8/26/94        dmh                Sync'd with the shipping 1.0.1 GX driver.
  9.      8/26/94        dmh                Universalized code.
  10. */
  11.  
  12. #include <Types.h>
  13. #include <QuickDraw.h>
  14. #include <Fonts.h>
  15. #include <Lists.h>
  16. #include <Devices.h>
  17. #include <Resources.h>
  18. #include <Script.h>
  19. #include <ToolUtils.h>
  20. #include <LowMem.h>
  21.  
  22. #ifndef __GXGRAPHICS__
  23.     #include <GXGraphics.h>
  24. #endif
  25. #ifndef __GXPRINTERDRIVERS__
  26.     #include <GXPrinterDrivers.h>
  27. #endif
  28.  
  29. #include "ChooserSupportProtos.h"
  30.  
  31.  
  32.  
  33.  
  34. #if defined(__MWERKS__)
  35.  
  36. #define        kLeftButton            0x08000000
  37. #define        kUsesOnAndOff        0x00100000
  38. #define        kAcceptsInit        0x00020000
  39. #define        kAcceptsTerminate    0x00000800
  40.  
  41. asm void __Startup__(void) ;
  42. asm void __Startup__(void)
  43. {
  44.     BRA.S    code                            // branch to our actual code
  45.     DC.W    169                                // device ID
  46.     DC.L    'PACK'                            // device Type
  47.     DC.W    0xF000                            // master ID for resources (-4096)
  48.     DC.W    2                                // version
  49.     DC.L    kLeftButton+kUsesOnAndOff+kAcceptsInit+kAcceptsTerminate    // flags
  50.         
  51. data:
  52.     ds.b    sizeof(PACKglobalRec)
  53. code:
  54.     MOVE.L    (a7)+,a0        // move return address into a0
  55.     PEA        data            // add a pointer to our global data onto stack as last parameter
  56.     MOVE.L    a0,-(a7)        // put the return address back on the stack
  57.     jmp        Device            // jump to it, so when it does the return, it goes to OUR caller
  58.     rts
  59. }
  60. #endif    
  61.  
  62.  
  63. // ------------------------------------------------------------------------
  64. // INTERNAL DEFINES
  65. // ------------------------------------------------------------------------
  66. // Chooser initialize message selector
  67. #define initializeMsg    11
  68.  
  69. // Icon Suite support
  70. #define ttNone        0x0000
  71. #define ttDisabled    0x0001
  72. #define    ttOffline    0x0002
  73. #define ttOpen        0x0003
  74. #define ttSelected     0x4000
  75. #define ttSelectedDisabled    (ttSelected + ttDisabled)
  76. #define ttSelectedOffline    (ttSelected + ttOffline)
  77. #define ttSelectedOpen        (ttSelected + ttOpen)
  78.  
  79. #define ttLabel0    0x0000
  80. #define ttLabel1    0x0100
  81. #define ttLabel2    0x0200
  82. #define ttLabel3    0x0300
  83. #define ttLabel4    0x0400
  84. #define ttLabel5    0x0500
  85. #define ttLabel6    0x0600
  86. #define ttLabel7    0x0700
  87.  
  88.  
  89. // Copy of the DrawText trap
  90. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  91.     = 0xA885; 
  92.  
  93. // ------------------------------------------------------------------------
  94. // MAIN CODE FOR PACK
  95. // ------------------------------------------------------------------------
  96. pascal OSErr Device(short message, short caller, StringPtr objName, 
  97.                     StringPtr zoneName, ListHandle theList, long p2, PACKglobalPtr global)
  98. {
  99.     
  100.     OSErr            anErr = noErr;
  101.  
  102.     if (message == initializeMsg)    // InitializeMsg--start up GX
  103.     {
  104.         FCBPBRec    pb;
  105.  
  106.     /*
  107.         Get the name of our driver for GXHandleChooserMessage.
  108.         (The user may have renamed us.)
  109.     */
  110.         pb.ioCompletion     = nil;
  111.         pb.ioNamePtr         = global->driverName;
  112.         pb.ioVRefNum         = 0;
  113.         pb.ioRefNum         = CurResFile();
  114.         pb.ioFCBIndx         = 0;
  115.         anErr = PBGetFCBInfo(&pb, false);
  116.  
  117.     /*
  118.         Clear *pJob, because it hasn't been initialized yet.  That doesn't
  119.         happen until we pass GXHandleChooserMessage an initializeMsg.
  120.     */
  121.         global->job = nil;
  122.  
  123.     /*
  124.         We need to initialize GX printing so that we can call
  125.         GXHandleChooserMessage.  Since printing requires a graphics
  126.         client, call GXEnterGraphics first.  If there are errors,
  127.         (for example, due to memory limitations), post an alert.
  128.     */
  129.         if (anErr == noErr)
  130.         {
  131.             GXEnterGraphics();
  132.             anErr = GXGetGraphicsError(nil);
  133.             if (anErr == noErr)
  134.             {
  135.                 anErr = GXInitPrinting();
  136.                 if (anErr != noErr)
  137.                     GXExitGraphics();
  138.             }
  139.                 
  140.             if (anErr != noErr)
  141.                 StopAlert(-4095, nil);
  142.         }
  143.     }
  144.  
  145. /*
  146.     If the Chooser hasn't created a job yet, do nothing unless we were
  147.     sent an initializeMsg.  In its default implementation of
  148.     GXHandleChooserMessage, QuickDraw GX will create the job for our
  149.     driver when it receives an initializeMsg.  It will store a reference
  150.     to it in our pJob pointer.
  151.     
  152.     For all other messages, if a job has been created, call
  153.     GXHandleChooserMessage to handle things.
  154. */
  155.     if (anErr == noErr)
  156.     {
  157.         if ((global->job != nil) || (message == initializeMsg))
  158.         {
  159.             anErr = GXHandleChooserMessage(&(global->job), global->driverName, message, caller, objName, zoneName, theList, p2);
  160.     
  161.         /*
  162.             If we just got a terminateMsg, and p2 is also terminateMsg, the
  163.             Chooser is closing.  QuickDraw GX just disposed of the gxJob it
  164.             created earlier when GXHandleChooserMessage was passed
  165.             initializeMsg, so we just need to call GXExitPrinting and
  166.             GXExitGraphics to clean up.
  167.             
  168.             Note that we must test the p2 parameter, because the Chooser
  169.             can also send terminateMsg when it wants to empty the device
  170.             list, but not dispose of us.  For example, this will happen
  171.             when the user turns off AppleTalk in the Chooser.
  172.         */
  173.             if ((message == terminateMsg) && (p2 == terminateMsg))
  174.             {
  175.                 GXExitPrinting();
  176.                 GXExitGraphics();
  177.             }
  178.         }
  179.     }
  180.         
  181.     return anErr ;
  182.     
  183. } // Device
  184.  
  185.  
  186.  
  187.